<template>
	<view class="page" :class="themeStyle">
		<!-- #ifdef APP-PLUS || MP -->
		<view class="page-header">
			<!-- <ns-navbar :is-back="!1" :title="diyData.global.title"
				:background="{ background: diyData.global.bgTopColor }" :title-color="diyData.global.textColor"
				:border-bottom="false" z-index="1001"></ns-navbar> -->
		</view>
		<!-- #endif -->

		<view v-for="(item, index) in diyData.value" :key="index">
			<template v-if="item.controller == 'GoodsCategory'">
				<!-- 商品分类 -->
				<diy-goods-level-category :value="item" @netFinish="netFinish" :autoHeight="!1" :bottom="windowHeight">
				</diy-goods-level-category>
			</template>
		</view>
		<view class="page-bottom">
			<diy-bottom-nav></diy-bottom-nav>
		</view>
		<loading-cover ref="loadingCover"></loading-cover>


		<!-- 底部tabBar -->
		
	</view>
</template>

<script>
	import diyGoodsLevelCategory from "@/components/diy-goods-level-category/diy-goods-level-category.vue";
	import diyBottomNav from '@/components/diy-bottom-nav/diy-bottom-nav.vue';
	import nsNavbar from '@/components/ns-navbar/ns-navbar.vue';
	export default {
		components: {
			diyBottomNav,
			diyGoodsLevelCategory,
			nsNavbar,
		},
		data() {
			return {
				diyData: [],
				windowHeight: 0
			};
		},
		computed: {
			// 使用对象展开运算符将此对象混入到外部对象中
			themeStyle() {
				return 'theme-' + this.$store.state.themeStyle
			}
		},
		onLoad() {
			this.getDiyInfo()
			this.getHeight()
		},
		onShow() {
			this.$langConfig.refresh();
			if (this.$refs.goodsLevelCategory) this.$refs.goodsLevelCategory[0].getCartData();
		},
		methods: {
			getHeight() {
				var self = this;
				uni.getSystemInfo({
					success: function(res) {
						self.windowHeight = res.windowHeight - 57;
						// if(self.iphoneX){
						// 	self.windowHeight = self.windowHeight -33;
						// }
					}
				});
			},
			//监听子组件分类列表是否请求完成
			netFinish(e) {
				if (e) {
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
				setTimeout(() => {
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}, 1000)
			},
			getDiyInfo() {
				this.$api.sendRequest({
					url: '/api/diyview/info',
					data: {
						name: 'DIYVIEW_GOODS_CATEGORY',
					},
					success: res => {
						if (res.code != 0 || !res.data) {
							if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
							return;
						}
						this.diyData = res.data;

						if (this.diyData.value) {
							this.diyData = JSON.parse(this.diyData.value);
							for (var i = 0; i < this.diyData.value.length; i++) {
								if (this.diyData.value[i].controller == 'PopWindow') {
									setTimeout(() => {
										if (uni.getStorageSync('index_wap_floating_layer') != null &&
											uni.getStorageSync(
												'index_wap_floating_layer') != '') {
											var wap_floating_cookie = JSON.parse(uni.getStorageSync(
												'index_wap_floating_layer'));
											if (wap_floating_cookie.closeNum < 3) {
												this.$refs.uniPopup[0].open();
											}
										} else {
											this.$refs.uniPopup[0].open();
										}
									}, 500);
									break;
								}
							}
							uni.setNavigationBarTitle({
								title: this.diyData.global.title
							})
						}
					},
				});
			},
		}
	};
</script>

<style lang="scss">
	/deep/.uni-popup__wrapper.uni-custom .uni-popup__wrapper-box {
		background: transparent;
	}

	/* #ifdef APP-PLUS || MP */
	.page-header {
		padding-top: 70rpx;
	}

	/* #endif */
</style>
